package com.tanhua.server.controller;


import com.tanhua.model.domain.Settings;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;


    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/questions")
    public ResponseEntity question(@RequestBody Map map) {
        String content = (String) map.get("content");
        settingsService.save(content);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "10") int size){
        PageResult pageResult=settingsService.page(page,size);
        return ResponseEntity.ok(pageResult);
    }

    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity delete(@PathVariable("uid") Long id){
        settingsService.deleteBlacklist(id);
        return ResponseEntity.ok(null);
    }

    //通知设置
    @PostMapping("/notifications/setting")
    public ResponseEntity setting(@RequestBody Settings settings){
        settingsService.setting(settings);
        return ResponseEntity.ok(null);
    }

}
